<div class="container">
    <h2>Admin Reporting</h2> 
     <div class="row">
	<div class="col-lg-12">
	<h3>Buying Invoice</h3>
           <div class="table-responsive">
			<table class="table table-bordered table-hover table-striped">
				<thead>
					<tr>
				        
					<td><b>	Product ID </b></td>
					<td><b>	Product Name </b></td>
					<td><b>	Item Buy Price (minprice) </b></td>
					<td><b>	Cost (maxnumber) </b></td>
					<td><b>	Total Cost (minprice x maxnumber)</b></td> 
								
           			</tr>
           		</thead>
           <tbody>
				 <?php 
				 $totalAllProductsCost = 0;
				 foreach ($products as $product) {
					$totalProductCost = $product->minprice * $product->maxnumber;
					$totalAllProductsCost += $totalProductCost;
			?>
                <tr>
                    <td><?php if (isset($product->product_id)) echo htmlspecialchars($product->product_id, ENT_QUOTES, 'UTF-8'); ?></td>
					<td><?php if (isset($product->product_name_ar)) echo htmlspecialchars($product->product_name_ar, ENT_QUOTES, 'UTF-8'); ?></td>
                    <td><?php if (isset($product->minprice)) echo htmlspecialchars($product->minprice, ENT_QUOTES, 'UTF-8'); ?></td>
					<td><?php if (isset($product->maxnumber)) echo htmlspecialchars($product->maxnumber, ENT_QUOTES, 'UTF-8'); ?></td>
					<td><?php echo $totalProductCost ?></td>
               </tr>
            <?php } ?>

            	<tr>
            		<td colspan="4" align="right"><b>Total Products Cost &nbsp;&nbsp;&nbsp;</b></td>
            		<td>
            			<?php print $totalAllProductsCost; ?></td>
            		</td>
            	</tr>
            </tbody>
          </table>
    </div>
	</div></div>
	<div class="row">
		<div class="col-lg-12">
		<h3>Selling Invoice</h3>
	           <div class="table-responsive">
				<table class="table table-bordered table-hover table-striped">
					<thead>
						<tr>
					        
						<td><b>	Product ID </b></td>
						<td><b>	Product Name </b></td>
						<td><b>	Item Sell Price (maxprice)</b></td>
						<td><b>	Sold Items Count </b></td>
						<td><b>	Total Cost (sold_items_count x maxprice))</b></td> 
									
	           			</tr>
	           		</thead>
	           <tbody>
	            <?php
	            		$totalAllSoldProducts = 0;
					 foreach ($products as $product) {
					 	$totalSoldProduct = $product->sold_items_count * $product->maxprice;
						$totalAllSoldProducts += $totalSoldProduct;
				?>
	                <tr>
	                    <td><?php if (isset($product->product_id)) echo htmlspecialchars($product->product_id, ENT_QUOTES, 'UTF-8'); ?></td>
						<td><?php if (isset($product->product_name_ar)) echo htmlspecialchars($product->product_name_ar, ENT_QUOTES, 'UTF-8'); ?></td>
	                    <td><?php if (isset($product->maxprice)) echo htmlspecialchars($product->maxprice, ENT_QUOTES, 'UTF-8'); ?></td>
						<td><?php if (isset($product->sold_items_count)) echo htmlspecialchars($product->sold_items_count, ENT_QUOTES, 'UTF-8'); ?></td>
						<td><?php echo $totalSoldProduct ?></td>
	               </tr>
	            <?php } ?>
	
	            	<tr>
	            		<td colspan="4" align="right"><b>Total Sold Products Amount &nbsp;&nbsp;&nbsp;</b></td>
	            		<td>
	            			<?php print $totalAllSoldProducts; ?>
	            		</td>
	            	</tr>
	            </tbody>
	          </table>
	    </div>
		</div>
	</div>
	
	<div class="row">
		<div class="col-lg-6">
		<h3>Balance Report</h3>
	           <div class="table-responsive">
				<table class="table table-bordered table-hover table-striped">
					<tr>
						<td><b>	Total Products Cost</b></td>
						<td><b>	<?php print $totalAllProductsCost; ?></b></td>
	           		</tr>
	           		<tr>
						<td><b>	Total Sold Items Amount</b></td>
						<td><b>	<?php print $totalAllSoldProducts; ?></b></td>
	           		</tr>
	           		<?php 
	           		$balance = $totalAllSoldProducts - $totalAllProductsCost;;
	           		if($balance > 0)
	           			$color = "green";
	           		else
	           			$color = "red";
	           		?>
	           		<tr>
						<td><b>	Balance</b></td>
						<td><span style="color:<?php print $color; ?>"><b>	<?php print $balance; ?></b></span></td>
	           		</tr>
	            </tbody>
	          </table>
	    </div>
		</div>
	</div>
</div>
</div>
